//
//  RwdMainTabBarController.swift
//  Weibo_rwd
//
//  Created by 任文迪 on 16/7/9.
//  Copyright © 2016年 spaceX. All rights reserved.
//

import UIKit
import SVProgressHUD

class RwdMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //设置背景颜色看一下是否创建成功
//        tabBarController?.tabBar.backgroundColor = UIColor.darkGrayColor()
        
//        self.tabBar = RwdtabBar//这个是一个只读属性  需要用 kvc 来改
        
        
        
        let rwdTabBar = RwdtabBar()
        
        rwdTabBar.composeButtonClosure = { [weak self] in
            
            if !RwduserAccountViewModel.shareUserAccount.isLogin {
                
                SVProgressHUD.showErrorWithStatus("请先登录亲")
                return
            }
            print("闭包打印的")
            
            let composeView = RwdcomposeView()
            
            let window = UIApplication.sharedApplication().windows.last!
            
            window.addSubview(composeView)
            
        }
        
        setValue(rwdTabBar, forKey: "tabBar")
        
        //添加child控制器
        addChildViewController(RwdHomeController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(RwdMessageController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(RwdDiscoverController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(RwdProfileController(), title: "我的", imageName: "tabbar_profile")
        
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func addChildViewController(childController: UIViewController,title:String ,imageName:String) {
        //设置下方控制器的图片和标题
        childController.tabBarItem.title = title
        //设置navigationcontroller的title
        childController.title = title
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置选中图片
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        //设置文字的大小
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(13)], forState: .Normal)
        
        //设置导航控制器
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
